package com.example.service.imp;

import com.example.mapper.StudentMapper;
import com.example.entity.Student;
import com.example.service.StudentService;
import com.example.service.ex.PasswordNotMatchException;
import com.example.service.ex.StudentNotFound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentImp implements StudentService {

   @Autowired
   private StudentMapper studentMapper;

    @Override
    public Student login(String username, String password) {
        Student result = studentMapper.findByName(username);
        if (result == null){
            throw new StudentNotFound("id信息未找到");
        }
        String oldPassword = result.getPassword();
        if(!password.equals(oldPassword)){
            throw new PasswordNotMatchException("密码错误");
        }
        Student student = new Student();
        student.setId(result.getId());
        student.setUsername(result.getUsername());
        student.setPassword(result.getPassword());
        return student;
    }
}
